/**
 * 
 */
package com.lehecai.core.api.lottery;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.LotteryType;
import com.lehecai.core.lottery.PlayType;

/**
 * @author hanwenda
 *
 */
public class XyscPrize extends AbstractApiResultBean {
	public static final String QUERY_LOTTERY_TYPE = "lottery_type";
	public static final String QUERY_PLAY_TYPE = "play_type";
	public static final String QUERY_PHASE = "phase";
	public static final String QUERY_VALUE = "value";

	private LotteryType lotteryType;//方案类型
	private PlayType playType;		//玩法类型
	private	String phase;			//彩期编号
	private String value;           //数值
	
	public XyscPrize() {
	}
	
	public XyscPrize(LotteryType lotteryType, PlayType playType, String phase,
			String value) {
		super();
		this.lotteryType = lotteryType;
		this.playType = playType;
		this.phase = phase;
		this.value = value;
	}
	
	public LotteryType getLotteryType() {
		return lotteryType;
	}

	public void setLotteryType(LotteryType lotteryType) {
		this.lotteryType = lotteryType;
	}

	public PlayType getPlayType() {
		return playType;
	}

	public void setPlayType(PlayType playType) {
		this.playType = playType;
	}

	public String getPhase() {
		return phase;
	}

	public void setPhase(String phase) {
		this.phase = phase;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public static XyscPrize convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		XyscPrize prize = new XyscPrize();
		prize.setLotteryType(LotteryType.getItem(getInt(object, "lottery_type")));
		prize.setPlayType(PlayType.getItem(getInt(object, "play_type")));
		prize.phase = getString(object, "phase");
		prize.setValue(getString(object, "value"));
		return prize;
	}
	
	@SuppressWarnings("unchecked")
	public static List<XyscPrize> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<XyscPrize> list = new ArrayList<XyscPrize>();
		for (Iterator iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}
}
